package com.csgc.camera.util

import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Date


object TimeUtil {

    fun dateFormatYMDHMs(time: Long) : String {
        val df = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
        return df.format(time)
    }
    fun dateFormatMD(time: Long) : String {
        val df = SimpleDateFormat("MM/dd")
        return df.format(time)
    }

    fun dateFormatMDHM(time: Long) : String {
        val df = SimpleDateFormat("MM/dd HH:mm")
        return df.format(time)
    }

    fun dateFormatCurrentYMD():String{
        val time = System.currentTimeMillis()
        val df = SimpleDateFormat("yyyy/MM/dd")
        return df.format(time)
    }
    fun dateFormatCurrentYMDHm():String{
        val time = System.currentTimeMillis()
        val df = SimpleDateFormat("yyyy-MM-dd HH:mm")
        return df.format(time)
    }
    fun dateFormatCurrentHM():String{
        val time = System.currentTimeMillis()
        val df = SimpleDateFormat("HH:mm")
        return df.format(time)
    }
    fun dateFormatHM(date:Long):String{
        val df = SimpleDateFormat("HH:mm")
        return df.format(date)
    }


    fun dateFormatCurrentWeek():String{
        val time = System.currentTimeMillis()
        val df = SimpleDateFormat("EEEE")
        return df.format(time)
    }

    fun dateOfWeek(date:Long):String{
        val df = SimpleDateFormat("EEEE")
        return df.format(date)
    }

    fun getCurrentTimeFormat(pattern:String):String{
        val time = System.currentTimeMillis()
        val df = SimpleDateFormat(pattern)
        return df.format(time)
    }
    fun getTimeFormat(time:Long,pattern:String):String{
        val df = SimpleDateFormat(pattern)
        return df.format(time)
    }


    fun changeTime(year:Int,month:Int,day:Int,hour:Int,min:Int):Long{
        val date = Calendar.getInstance()
        date.set(Calendar.YEAR,year)
        date.set(Calendar.MONTH,month-1)
        date.set(Calendar.DAY_OF_MONTH,day)
        date.set(Calendar.HOUR_OF_DAY,hour)
        date.set(Calendar.MINUTE,min)

        return date.timeInMillis
        //XLog.e("======date${getTimeFormat(date.timeInMillis, MaskDateStyle.DateWeek.pattern)}")
    }


    fun changeIsoTime(time:String):String{
        if (time.isEmpty()){
            return ""
        }
        val format = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
        val date: Date = format.parse(time)

        val df = SimpleDateFormat("yyyy-MM-dd")

        return df.format(date)
    }

}